package csu.web.mypetstore.persistence.impl;

import csu.web.mypetstore.domain.Log;
import csu.web.mypetstore.persistence.DBUtil;
import csu.web.mypetstore.persistence.LogDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class LogDaoImpl implements LogDao {
    private static final String INSERT_LOG = "INSERT INTO LOG (username,loginf) VALUES ( ? , ? )";
    @Override
    public void insertLog(Log log) {
        Connection connection = DBUtil.getConnection();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(INSERT_LOG);
            preparedStatement.setString(1,log.getUserName());
            preparedStatement.setString(2,log.getLogInf());
            int isSucceed = preparedStatement.executeUpdate();
            if(isSucceed==0){
                System.out.println("insert log failed!");
            }
            DBUtil.closeStatement(preparedStatement);
            DBUtil.closeConnection(connection);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
